import 'package:cbec_app/components/base/base_chekbox.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/entity/user_center/coupon_item_entity.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_rx/src/rx_typedefs/rx_typedefs.dart';
import 'coupon_shape_border.dart';

/**
 * 单个优惠券
 */
class CouponItem extends StatefulWidget {
  // final String price;//金额
  // final String needMoney;//满多少可使用
  // final String start_time;//开始时间
  // final String end_time;//结束时间
  // final String title;//优惠券标题
  // final String sub_title;//副标题
  // final String desc;//使用说明

  final int status; //状态
  // final String status_tetx;//状态文本

  final CouponItemEntity item;

  final VoidCallback onClick;

  final bool? hasCheckbox;

  const CouponItem({super.key, required this.status, required this.item, required this.onClick, this.hasCheckbox = false});

  @override
  State<CouponItem> createState() => _CouponItemState();
}

class _CouponItemState extends State<CouponItem> {
  bool _is_open = false;
  Icon _icons = const Icon(Icons.keyboard_arrow_down, color: Color.fromRGBO(153, 153, 153, 1));

  late Color buttonColor;
  late String txt;

  @override
  Widget build(BuildContext context) {
    // print("这里");
    // if(widget.item.validityStartTime==null){
    //   print(widget.item.validityType);
    // }

    switch (widget.status) {
      case 1:
        //待开始
        buttonColor = Tools.fromHex("#FE5568");
      case 2:
        //进行中
        buttonColor = Tools.fromHex("#FE5568");
      case 3:
        //已结束
        buttonColor = Tools.fromHex("#CCCCCC");
      case 4:
        //去领取
        buttonColor = Tools.fromHex("#FE5568");
        txt = "去领取";
      default:
        buttonColor = Tools.fromHex("#FE5568");
        txt = "去领取";
    }
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ClipPath(
          clipper: ShapeBorderClipper(
            shape: CouponShapeBorder(),
          ),
          child: Container(
              // width: 375.w,
              height: 90.h,
              constraints: BoxConstraints(maxHeight: 200.w),
              margin: EdgeInsets.only(bottom: 10.w),
              color: const Color.fromRGBO(255, 255, 255, 1),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      //左
                      Container(
                        width: 94.w,
                        padding: EdgeInsets.only(top: 5.w, bottom: 5.w),
                        color: buttonColor,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [Text("${widget.item.drop}", style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w700, color: Colors.white)), Text("${widget.item.content}", style: const TextStyle(fontSize: 12, color: Colors.white))],
                        ),
                      ),
                      //中
                      Container(
                        width: 130.w,
                        margin: EdgeInsets.fromLTRB(10.w, 0.w, 35.w, 0.w),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(widget.item.name!, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color.fromRGBO(51, 51, 51, 1)), overflow: TextOverflow.ellipsis, maxLines: 1),
                            Text(widget.item.goodsType!, style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(102, 102, 102, 1))),
                            // SizedBox(height: 2.w),
                            widget.item.validityType != '3' && widget.item.validityType != '4' && widget.item.validityStartTime != null
                                ? Row(
                                    children: [
                                      SizedBox(
                                        width: 55.w,
                                        child: Text("${widget.item.validityStartTime}", style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(102, 102, 102, 1))),
                                      ),
                                      Container(
                                        margin: EdgeInsets.only(left: 5.w, right: 5.w),
                                        child: const Text("—", style: TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(102, 102, 102, 1))),
                                      ),
                                      SizedBox(
                                        width: 55.w,
                                        child: Text("${widget.item.validityEndTime}", style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(102, 102, 102, 1))),
                                      ),
                                    ],
                                  )
                                : emptyWidget(),
                          ],
                        ),
                      ),
                    ],
                  ),
                  //右【按钮】
                  widget.hasCheckbox == false
                      ? Container(
                          margin: EdgeInsets.only(right: 10.w),
                          height: 24,
                          child: ElevatedButton(
                            style: ButtonStyle(
                                //
                                backgroundColor: MaterialStateProperty.all(buttonColor)),
                            onPressed: widget.onClick,
                            child: const Text('去领取', style: TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Colors.white)),
                          ))
                      : Container(
                          margin: EdgeInsets.only(right: 30.w),
                          child: BaseCheckBox(value: false),
                        )
                ],
              )),
        ),
        Visibility(
            visible: _is_open, //couponCtr.isCloses.value,
            child: Container(
              padding: EdgeInsets.only(left: 110.w),
              alignment: Alignment.topLeft,
              width: 375.w,
              margin: EdgeInsets.fromLTRB(10.w, 0.w, 10.w, 5.w),
              child: Text(widget.item.goodsType!, style: const TextStyle(fontSize: 11, fontWeight: FontWeight.w300, color: Color.fromRGBO(102, 102, 102, 1))),
            ))
      ],
    );
  }

  //获取优惠券针对用户
  String getType() {
    switch (widget.item?.targetType) {
      case 1:
        return '全场可用';
      case 2:
        return '权益卡会员可用';
      case 3:
        return '普通会员可用';
      case 4:
        return '新用户可用';
      case 5:
        return '部分用户参与';
      case 6:
        return '部分用户不参与';
      default:
        return '默认';
    }
  }
}
